#ifndef USERPROFILE_H
#define USERPROFILE_H

#include <QObject>
#include "filetransfer/downloader.h"

class UserProfile : public QObject
{
    Q_OBJECT
public:
    enum {
        Offline = -1,
        OnlineWeb = 1,
        OnlineMobile = 2
    };

    explicit UserProfile(QObject *parent = 0);
    UserProfile(const qint64 userId, const QString& userName, const QString& displayName, const QString& avatar, QObject* parent =0);
    UserProfile(const UserProfile& uProfile);

    bool operator==(const UserProfile& uProfile) const {
        return _userId == uProfile.getUserId() ? true :false;
    }

    bool operator<=(const UserProfile & other) const {
        return this->getDisplayName().trimmed().toLower() <= other.getDisplayName().trimmed().toLower() ? true : false;
    }

    inline int getUserId() const {
        return _userId;
    }

    inline QString getUserName()const{
        return _userName;
    }

    inline QString getDisplayName() const {
        return _displayName;
    }

    inline QString getAvatar() const {
        return _avatar;
    }

    inline QString getAvatarLocal() const {
        return _avatarLocal;
    }

    inline void setAvatarLocal(const QString& avatarLocal){
        _avatarLocal = avatarLocal;
    }

    inline void setBaseInfo(const qint64 userId,
                            const QString& userName,
                            const QString& displayName,
                            const QString& avatar)
    {
        _userId = userId;
        _userName = userName;
        _displayName = displayName;
        _avatar = avatar;
    }

    inline void setUserId(const qint64 userId){
        _userId = userId;
    }

    inline QString getMessageStatus() const {
        return _messageStatus;
    }

    inline qint64 getTime() const {
        return _time;
    }

    inline int getSenderMsg() const {
        return _senderMsg;
    }

    inline int getTypeMsg() const {
        return _typeMsg;
    }

    inline int getOnline() const {
        return _online;
    }

    inline int  getTotalMember() const {
        return _totalMember;
    }

    inline QList <qint64> getListGroupMember() const {
        return _listGroupMember;
    }

    inline void setMessageStatus( QString messageStatus)  {
        _messageStatus = messageStatus;
    }

    inline void setTime(qint64 time) {
        _time = time;
    }

    inline void setSenderMsg(int senderMsg) {
        _senderMsg = senderMsg;
    }

    inline void setTypeMsg(int typeMsg) {
        _typeMsg = typeMsg;
    }

    inline void setOnline(int online) {
        _online = online;
    }

    inline void setTotalMember(int totalMember) {
        _totalMember = totalMember;
    }

    inline void setListGroupMember(QList<qint64> listGroupMember) {
        _listGroupMember = listGroupMember;
    }

    void downloadImageAndUpdateLocal();
    void updateData2Local();
private:

signals:

    void changedUserId();
    void changedUserName();
    void changedDisplayName();
    void changedAvatar();
    void updateLocalFinish();
    void sortListFriend();

public slots:
    void onImageDownloaded(const QString &error,bool aborted,bool paused);
    void onDownloadProgress(qint64 received, qint64 total);

private:
    qint64 _userId;
    QString _userName;
    QString _displayName;
    QString _avatar;
    QString _avatarLocal;
    QString _messageStatus;
    qint64 _time;
    int _senderMsg;
    int _typeMsg;
    int _online; // -1 offline, 1 web, 2 mobile
    int _totalMember;//1 private, >=2 group
    QList <qint64> _listGroupMember;

    FileTransfer::DownLoader * _downloader;
};

#endif // USERPROFILE_H
